<?php

include( "./admin/include/func.php");

$db = new db();
if (! $db->connect()) exit( mysql_error());
   
$db->sql = "SELECT id,nev,slug,`order`,parent
            FROM rovat 
            WHERE parent=0
            ORDER BY `order`";
$db->query();

$forovatok = array ();
while ($row = mysql_fetch_array($db->rs)) {
	$forovatok[] = $row;	
}
 
for ($i=0;$i<count($forovatok);$i++) {
	$db->sql = "SELECT id,nev,slug,`order`,parent
				FROM rovat 
				WHERE parent='".$forovatok[$i]['id']."'
				ORDER BY `order`";
	$db->query();
	$forovatok[$i]['childs'] = array ();
	while ($row = mysql_fetch_array($db->rs)) {
		$forovatok[$i]['childs'][] = $row;	
	}	
}

?>

<?php include ("header.php"); ?>

<?php include ("top.php"); ?>

<?php include ("left.php"); ?>
							
<div id="middle">

<p id="bhead">Válasszon rovatot</p>

<?php 

if (count($forovatok) < 1) print "Nincsennek rovatok!";

for ($i=0;$i<count($forovatok);$i++) {
	if (! ($i % 2)) print "<div class='rovatblock'>";
	$forovat = $forovatok[$i];
	print "<div class='rovatok'>";
	print "<p class='forovat'><a href='hirdetesek.php?rovat=".$forovat['slug']."'>".$forovat['nev']."</a></p>";
	$alrovatok = $forovat['childs'];
	foreach ($alrovatok as $alrovat) {
		print "<p class='alrovat'><a href='hirdetesek.php?rovat=".$alrovat['slug']."'>".$alrovat['nev']."</a></p>";
		//$db->sql = "UPDATE rovat SET slug='".slug($alrovat['nev'])."' WHERE id=".$alrovat['id']; 
		//$db->query();
	}
	print "</div>";
	if ($i % 2 || $i == (count($forovatok) - 1)) print "<br /><hr /></div>";

	//$db->sql = "UPDATE rovat SET slug='".slug($forovat['nev'])."' WHERE id=".$forovat['id']; 
	//$db->query();
}

?>
 
<br />

</div>

<?php include ("right.php"); ?>

<?php include ("footer.php"); ?>
